<?php
/**
 * Created by PhpStorm.
 * User: t
 * Date: 2024/4/17
 * Time: 14:02
 * @copyright: ©2024 永州微聚商网络科技有限公司
 * @link: https://www.weijuyunke.com
 */
namespace app\admin\controller;

use app\home\model\IntegralLog;
use app\home\model\SignConfig;
use app\home\model\SignLog;
use app\Request;


class Sign
{

    public function signConfig(Request $request)
    {
        $signModel = new SignConfig();
        $list = $signModel->select();
        $count = $signModel->count();
        return adminSuccess('签到配置', ['list' => $list, 'count' => $count]);
    }

    public function signLog(Request $request)
    {
        $param = $request->param();
        $limit = 10;
        $start = 0;
        $where= [];
        if (isset($param['name']) && !empty($param['name'])){
            $where[] = ['wachat_nickname|nickname','like','%'.$param['name'].'%'];
        }

        if (isset($param['limit']) && !empty($param['limit'])) {
            $limit = $param['limit'];
        }
        if (isset($param['page']) && !empty($param['page'])) {
            $start = ($param['page'] - 1) * $limit;
        }
        $signLogModel = new SignLog();
        $info = $signLogModel->alias('s')
            ->where($where)
            ->field('s.*,u.phone,u.wachat_nickname,u.nickname')
            ->leftJoin('user u', 'u.id = s.uid')
            ->order('create_time', 'desc')->limit($start,$limit)->select()->toArray();
       //echo  $signLogModel->getLastSql();exit;
        $count = $signLogModel->alias('s')
            ->where($where)
            ->field('s.*,u.phone.u.wachat_nickname,u.nickname')
            ->leftJoin('user u', 'u.id = s.uid')
             ->count();
        return adminSuccess('签到记录', ['list' =>$info,'count'=> $count ]);
    }


    public function setSignConfig(Request $request){
        $param = $request->param();
        $signModel = new SignConfig();
        $signModel->where(['id' => $param['id']])
                ->update(['amount' =>$param['amount'] ]);

        return adminSuccess('修改成功');
    }

}